
import { createBrowserRouter, Navigate } from 'react-router-dom';
import BasicLayout from '../layouts/BasicLayout';
import Dashboard from '../pages/Dashboard';
import DataLineage from '../pages/DataLineage';
import Login from '../pages/Login';
import Register from '../pages/Register';
import UserManagement from '../pages/UserManagement';
import RoleManagement from '../pages/RoleManagement';
import PermissionManagement from '../pages/PermissionManagement';
import RouteManagement from '../pages/RouteManagement';
import DataSourceManagement from '../pages/DataSourceManagement';
import SyncTaskManagement from '../pages/SyncTaskManagement';
import SyncExecutionMonitor from '../pages/SyncExecutionMonitor';

import NotFound from '../pages/NotFound';
import UIShowcase from '../components/UIShowcase';
import ProtectedRoute from '../components/ProtectedRoute';

// 创建路由配置
export const router = createBrowserRouter([
  // 认证相关路由（无需布局）
  {
    path: '/login',
    element: <Login />,
  },
  {
    path: '/register',
    element: <Register />,
  },
  // 主应用路由（需要认证）
  {
    path: '/',
    element: (
      <ProtectedRoute>
        <BasicLayout />
      </ProtectedRoute>
    ),
    children: [
      {
        index: true,
        element: <Navigate to="/dashboard" replace />,
      },
      {
        path: 'dashboard',
        element: <Dashboard />,
      },
      {
        path: 'lineage',
        element: (
          <ProtectedRoute permissions={['lineage.view']}>
            <DataLineage />
          </ProtectedRoute>
        ),
      },
      {
        path: 'users',
        element: (
          <ProtectedRoute permissions={['user.view']}>
            <UserManagement />
          </ProtectedRoute>
        ),
      },
      {
        path: 'roles',
        element: (
          <ProtectedRoute permissions={['role.view']}>
            <RoleManagement />
          </ProtectedRoute>
        ),
      },
      {
        path: 'permissions',
        element: (
          <ProtectedRoute permissions={['permission.view', 'role.create', 'role.update', 'role.delete']}>
            <PermissionManagement />
          </ProtectedRoute>
        ),
      },
      {
        path: 'routes',
        element: (
          <ProtectedRoute permissions={['route.view']}>
            <RouteManagement />
          </ProtectedRoute>
        ),
      },
      {
        path: 'datasources',
        element: (
          <ProtectedRoute permissions={['datasource.view']}>
            <DataSourceManagement />
          </ProtectedRoute>
        ),
      },
      {
        path: 'sync',
        children: [
          {
            path: 'tasks',
            element: (
              <ProtectedRoute permissions={['sync:task:view']}>
                <SyncTaskManagement />
              </ProtectedRoute>
            ),
          },
          {
            path: 'executions',
            element: (
              <ProtectedRoute permissions={['sync:execution:view']}>
                <SyncExecutionMonitor />
              </ProtectedRoute>
            ),
          },

        ],
      },
      {
        path: 'showcase',
        element: <UIShowcase />,
      },


    ],
  },
  {
    path: '*',
    element: <NotFound />,
  },
]);

export default router;
